package zhtt.demo01;

import javax.persistence.*;
import java.util.Date;

/**
 * Created by zhtt on 2017/4/18.
 */
@Entity
@Table(name=Student.TABLE_NAME)/** 此标签可以省略，表名则为student**/
public class Student {
    public static final String TABLE_NAME="zhtt12_student";

    @Id /** 属性注解，可以用在属性上，也可以用在属性的get方法上 **/
    /** 指定主键的生成策略
     * auto：自动生成，会创建一张hibernate_sequence表，需要手动初始化值，不然报错
     * identity：根据数据库中的Identity字段生成
     * sequence：使用序列
     * table：使用指定表，结合@TableGenerator使用。
     * **/
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column
    private Integer id;

    @Version/** 乐观锁 **/
    private int version;

    @Temporal(TemporalType.DATE)/** 指定时间格式：yyyy-mm-dd **/
    private Date createTime=new Date();

    @Transient/** 指定临时字段 **/
    private String createTimeStr;

    @Column(name="name",nullable = true,unique = false,length = 30)/** 映入到数据库中字段为name、允许为空、允许重复、字段长度为30  **/
    private String name;

    @Column(insertable = true,updatable = true,precision = 3,scale = 0)/** 出现在插入、更新语句中；数字长度为3，小数位数为0**/
    private Integer age;

//    @Column(columnDefinition = "fen shu")/** 指定注解  mysql不支持 **/
    private double score;

    public Student() {}

    public Student(Integer id) {
        this.id = id;
    }

    public Student(String name, int age, double score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public double getScore() {
        return score;
    }

    public void setScore(double score) {
        this.score = score;
    }

    public int getVersion() {
        return version;
    }

    public void setVersion(int version) {
        this.version = version;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }
}
